import React, { useEffect, useState } from 'react'
import request from './http/request'

export default function App() {
    let [loading, setLoading] = useState(false);
    let [repo, setRepo] = useState({});
    // componentDidMount发送
    useEffect(()=>{
        async function main(){
            // 发送请求前把loading设为true
            setLoading(true);
            let {items} = await request.get('/search/repositories',{
                params:{
                    q:'vue',
                    sort:'stars'
                }
            })
            setLoading(false);
            setRepo({name:items[0].name, url: items[0].html_url});
        }
        main();
    },[]);
    return (
        <div>
            {loading ? <h3>loading.....</h3> : <div>most star repo is <a href={repo.url}>{repo.name}</a></div>}
        </div>
    )
}
